/*
 * 文件名：PaymentMethodsInfoServiceImp.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：ozm
 * 修改时间：2013-1-28
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.reservation.payment.service.imp;

import javax.servlet.http.HttpServletRequest;
import org.springframework.dao.DataAccessException;
import com.wootide.cms.common.CMSRuntimeException;
import com.wootide.cms.common.ErrorCodes;
import com.wootide.cms.common.Page;
import com.wootide.cms.common.QueryCondition;
import com.wootide.cms.common.QueryResults;
import com.wootide.cms.common.Result;
import com.wootide.cms.common.util.CommonUtil;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.reservation.orderby.dao.OrderByInfoDao;
import com.wootide.cms.service.reservation.orderby.pojo.OrderByInfo;
import com.wootide.cms.service.reservation.orderby.service.OrderByInfoService;
import com.wootide.cms.service.reservation.orderby.transaction.OrderByInfoTransaction;
import com.wootide.cms.service.reservation.payment.dao.PaymentMethodsInfoDao;
import com.wootide.cms.service.reservation.payment.pojo.PaymentMethodsInfo;
import com.wootide.cms.service.reservation.payment.service.PaymentMethodsInfoService;
import com.wootide.cms.service.reservation.payment.transaction.PaymentMethodsInfoTransaction;

/**
 * 支付方式业务层实现层
 * 〈一句话功能简述〉
 * 〈功能详细描述〉
 * @author ozm
 * @version 2013-1-28
 * @see PaymentMethodsInfoServiceImp
 * @since 2013-1-28下午2:20:01
 */
public class PaymentMethodsInfoServiceImp implements PaymentMethodsInfoService
{
    // 注入运行日志
    private RunLog runLog;
    
    //用户事物层实例
    private PaymentMethodsInfoTransaction paymentMethodsInfoTransaction;
    
    //用户数据访问层实例
    private PaymentMethodsInfoDao paymentMethodsInfoDao;
    
   

    /**
     * 
     * Description: 分页查询
     * Implement: <br>
     * @param page 分页参数
     * @param queryConditon 查询条件
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午1:23:32
     */
    public Result queryForPages(Page page, QueryCondition queryConditon)
    {
        // 打印方法入口参数
        runLog.debug("page=" + page);
        runLog.debug("queryConditon=" + queryConditon);
        
        // 定义返回结果
        Result result = new Result();
        try
        {
            queryConditon = null == queryConditon? new QueryCondition() : queryConditon;
            queryConditon.setObjClass(PaymentMethodsInfo.class);
            QueryResults queryResults = paymentMethodsInfoTransaction.queryForPages(page,
                    queryConditon);
            result.setResultPojo(queryResults);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            runLog.info("Query PaymentMethodsInfo Success!");
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Query PaymentMethodsInfo Failed!", e);
            // 注册修改前的路由对象
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        
        catch (Exception e)
        {
            //异常
            runLog.error("Query PaymentMethodsInfo Failed!", e);
            // 注册修改前的路由对象
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    
    /**
     * 
     * Description: 添加一种支付方式
     * Implement: <br>
     * @param paymentMethodsInfo 要添加的支付方式
     * @param request HttpServletRequest
     * @return
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午1:26:06
     */
    public Result addOnePaymentMethods(PaymentMethodsInfo paymentMethodsInfo, HttpServletRequest request)
    {
        // 打印方法入口参数
        runLog.debug("paymentMethodsInfo=" + paymentMethodsInfo);
        Result result = new Result();
        try
        {
            paymentMethodsInfoTransaction.addOnePaymentMethods(paymentMethodsInfo);
            runLog.info("Add PaymentMethodsInfo Success! Input data:" + paymentMethodsInfo, request);
            
            // 设置返回码为成功
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Add PaymentMethodsInfo Failed! Input data:" + paymentMethodsInfo, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        catch (CMSRuntimeException e)
        {
            //运行时异常
            runLog.info("Add PaymentMethodsInfo Failed! Input Data:" + paymentMethodsInfo
                    + " Error Message:" + e.getMessage(), request);
            
            result.setResultCode(e.getErrorCode());
        }
        catch (Exception e)
        {
            //未知异常
            runLog.error("Add PaymentMethodsInfo Failed!Input data:" + paymentMethodsInfo, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    
    /**
     * 
     * Description: 修改一种支付方式
     * Implement: <br>
     * @param paymentMethodsInfo 要修点的支付方式
     * @param request HttpServletRequest
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午1:27:37
     */
    public Result modOnePaymentMethods(PaymentMethodsInfo paymentMethodsInfo, HttpServletRequest request)
    {
        // 打印方法入口参数
        runLog.debug("paymentMethodsInfo=" + paymentMethodsInfo);
        Result result = new Result();
        try
        {
            PaymentMethodsInfo oldPaymentMethodsInfo = paymentMethodsInfoTransaction.modOnePaymentMethods(paymentMethodsInfo);
            runLog.info("Mod PaymentMethodsInfo Success! Input data:" + paymentMethodsInfo
                    + "|oldDate:" + oldPaymentMethodsInfo, request);
            
            // 设置返回码为成功
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            
        }
        catch (DataAccessException e)
        {
            //数据库异常
            runLog.error("Mod PaymentMethodsInfo Failed! Input data:" + paymentMethodsInfo, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        catch (CMSRuntimeException e)
        {
            //自定义异常
            runLog.info("Mod PaymentMethodsInfo Failed! Input Data:" + paymentMethodsInfo
                    + " Error Message:" + e.getMessage(), request);
            result.setResultCode(e.getErrorCode());
        }
        catch (Exception e)
        {
            //位置异常
            runLog.error("Mod PaymentMethodsInfo Failed!Input data:" + paymentMethodsInfo, e, request);
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    }
    
    /**
     * 
     * Description: 通过索引查询一种支付方式
     * Implement: <br>
     * @param innerIndex 要查询一种支付方式的Id
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午3:55:17
     */
    public Result viewOnePaymentMethods(Integer innerIndex)
    {

        // 打印方法入口参数
        runLog.debug("innerIndex=" + innerIndex);

        Result result = new Result();
        try
        {
            PaymentMethodsInfo paymentMethodsInfo = paymentMethodsInfoTransaction.viewOnePaymentMethods(innerIndex);
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
            result.setResultPojo(paymentMethodsInfo);
        }
        catch (DataAccessException e)
        {
            runLog.error("Find One PaymentMethodsInfo Failed!", e);
            // 注册修改前的中文路由对象
            result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
        }
        catch (CMSRuntimeException e)
        {
            //自定义异常
            runLog.info("Mod PaymentMethodsInfo Failed! Input Data:" + innerIndex
                    + " Error Message:" + e.getMessage());
            result.setResultCode(e.getErrorCode());
        }
        catch (Exception e)
        {
            runLog.error("Find One PaymentMethodsInfo Failed!", e);
            // 注册修改前的中文路由对象
            result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
        }
        return result;
    
    }
    
    /**
     * 
     * Description: 删除支付方式
     * Implement: <br>
     * @param innerIndexs 要删除的支付方式id列表
     * @param request HttpServletRequest
     * @return
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午4:17:56
     */
    public Result delPaymentMethodss(Integer[] innerIndexs, HttpServletRequest request)
    {
        // 打印方法入口参数
        runLog.debug("innerIndexs = " + CommonUtil.toString(innerIndexs));
        
        Result result = new Result();
        
        result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
        // 定义删除失败的条数
        int delErrorNum = 0;
        
        for (Integer innerIndex : innerIndexs)
        {
            PaymentMethodsInfo paymentMethodsInfo = null;
            try
            {
                // 调用删除路由事务层
                paymentMethodsInfo = paymentMethodsInfoTransaction.delOnePaymentMethods(innerIndex);
                runLog.info("Delete PaymentMethodsInfo Success! orderByInfo = " + paymentMethodsInfo,
                        request);
                
            }
            catch (DataAccessException e)
            {
                //数据库异常
                delErrorNum++;
                runLog.error("Delete PaymentMethodsInfo Failed! Innerindex = " + innerIndex,
                        e,
                        request);
                
                result.setResultCode(ErrorCodes.ERRORCODE_DATABASE);
                
            }
            catch (CMSRuntimeException e)
            {
                //运行时异常
                runLog.info("Delete PaymentMethodsInfo Failed! Innerindex = " + innerIndex
                        + " Error Message:" + e.getMessage(), request);
                result.setResultCode(e.getErrorCode());
                
            }
            catch (Exception e)
            {
                //未知异常
                delErrorNum++;
                runLog.error("Delete PaymentMethodsInfo Failed!  Innerindex = " + innerIndex,
                        e,request);
                result.setResultCode(ErrorCodes.ERRORCODE_UNKNOW);
                
            }
        }
        // 返回失败的条数
        result.setDelErrorNum(delErrorNum);
        return result;
    }

    /**
     * 
     * Description: 新增一种支付方式唯一性验证
     * Implement: <br>
     * @param content 支付方式名称
     * @return
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-31下午1:41:22
     */
    public Result checkContentWhenAdd(String content)
    {
        
        // 打印方法入口参数
        runLog.debug("content=" + content);

        int num = paymentMethodsInfoDao.findNumByPaymentMethodsByName(content);
        Result result = new Result();
        // 如果已存在
        if (num > 0)
        {
            runLog.info("Illegal!PaymentMethodsInfo Has Existed! Input Data:" + content);
            
            result.setResultCode(ErrorCodes.Reservation.OrderBy.ORDERBYEXIST);
        }
        // 如果不存在
        else
        {
            runLog.info("Legal!PaymentMethodsInfo Not Existed! Input Data:" + content);
           
            result.setResultCode(ErrorCodes.ERRORCODE_SUCC);
        }
        return result;
    }
    
    public RunLog getRunLog()
    {
        return runLog;
    }

    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }

    public PaymentMethodsInfoTransaction getPaymentMethodsInfoTransaction()
    {
        return paymentMethodsInfoTransaction;
    }

    public void setPaymentMethodsInfoTransaction(
            PaymentMethodsInfoTransaction paymentMethodsInfoTransaction)
    {
        this.paymentMethodsInfoTransaction = paymentMethodsInfoTransaction;
    }

    public PaymentMethodsInfoDao getPaymentMethodsInfoDao()
    {
        return paymentMethodsInfoDao;
    }

    public void setPaymentMethodsInfoDao(PaymentMethodsInfoDao paymentMethodsInfoDao)
    {
        this.paymentMethodsInfoDao = paymentMethodsInfoDao;
    }

 
   

   
}
